KMG.SceneSwitch = function ( ) {

	this.index = -1;
	this.scenes = [];

	this.preScene = null;
	this.curScene = null;
	function exitCallBack( sender )
	{
		if (sender.preScene != null) {
			sender.preScene.setVisible(false);
		}
		if (sender.curScene != null) {
			sender.curScene.setVisible(true);
		}
	}
	function enterCallBack( )
	{

	}

	this.add = function(scene)
	{
		this.scenes.push(scene);
	};

	this.switch = function(index)
	{
		var count = this.scenes.length;
		if (index >= count || index < 0) {
			return;
		}
		this.preScene = null;
		if (this.index >= 0) {
			this.preScene = this.scenes[this.index];
		}
		this.curScene = this.scenes[index];
		this.index = index;

		if (this.preScene != null) {
			this.preScene.exitScene(exitCallBack, this);
		} else {
			for (var i = 0; i < count; i++) {
				if (index != i) {
					this.scenes[i].setVisible(false);
				}
			}
		}
		if (this.curScene != null) {
			this.curScene.enterScene(enterCallBack, this);
		}
	};

};